package com.dingwei.superiordiary.mvp.presenter;

import android.text.TextUtils;

import com.dingwei.superiordiary.base.MyBaseBean;
import com.dingwei.superiordiary.bean.FailsBean;
import com.dingwei.superiordiary.bean.GoodsListBean;
import com.dingwei.superiordiary.custom.myCallback;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by lihao on 2017/9/12.
 */

public class RankingListFragmentPresenter extends basePresenter {

    private Contract.RankingListFragmentView rankingListFragmentView;

    public RankingListFragmentPresenter(Contract.RankingListFragmentView view) {
        super(view);
        this.rankingListFragmentView = view;
    }
    public void initData(int page, String category_id, String order, final boolean isRefresh, boolean isShowDiaog){
        RequestParams rp = new RequestParams(URLS.HOST+URLS.PRODUCT_LIST);
        rp.addBodyParameter("page",page+"");
        if (!TextUtils.isEmpty(category_id)) {
            rp.addBodyParameter("category_id",category_id);
        }
        if (!TextUtils.isEmpty(order)){
            rp.addBodyParameter("order",order);
        }
        x.http().post(rp, new myCallback(BaseActivity.context, GoodsListBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                GoodsListBean bean = (GoodsListBean) baseBean;
                if (isRefresh) {
                    rankingListFragmentView.onRefresh(bean);
                }else {
                    rankingListFragmentView.onLoadMore(bean);
                }
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
                rankingListFragmentView.onFail();
            }
        });
    }
}
